﻿using System;


namespace CalcLuckyNum
{
    class Program
    {
        static void Main()
        {
            // Generate random number , and  check  it for  lucky number  
            Random rnd = new Random();
            int minValue = 1000;
            int maxValue = 100000000;
            int number = rnd.Next(minValue, maxValue);
            Console.WriteLine("Случайное число: {0}", number);
            int counts = CalcDigitNum(number);
            CheckLuckyNum(number, counts);
            Console.ReadKey();
        }


        //calc digits number
        static int CalcDigitNum(int number)
        {
            int n = 0;
            while (number > 0)
            {
                number /= 10;
                n++;
            }
            return n;
        }

        static void CheckLuckyNum(int number, int counts)
        {
            int firstPart = 0;
            int lastPart = 0;
            if (counts > 3 & counts % 2 == 0)
            {
                int i = counts / 2;
                double j = Math.Pow(10, i);
                int number1 = number / (int)j;
                while (i > 0)
                {
                    firstPart = firstPart + number1 % 10;
                    lastPart = lastPart + number % 10;
                    number /= 10;
                    number1 /= 10;
                    i--;
                }

                if (firstPart == lastPart) { Console.WriteLine("Это удача, счастливое число! {0} = {1}.", firstPart, lastPart); }
                else
                {
                    Console.WriteLine("Это число не счастливое, {0} не равно {1}", firstPart, lastPart);
                }
            }
            else
            {
                Console.WriteLine("Это число не подходит.");
            }
        }
    }
}
